/**
 * 2013，thor.com，all rights reserved。
 * 
 * Project：		thor-common
 * Filename：	QueryCondition.java
 * Created：		2013-11-11
 * Creator：		thor
 */
package com.jeecg.query;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author thor
 * 
 */
public class QueryCondition implements Serializable {
  private static final long serialVersionUID = -3847520089147872938L;

  public QueryCondition() {

  }

  public QueryCondition(String operation, Object... parameters) {
    setOperation(operation);
    addParameter(parameters);
  }

  private String operation;
  private List<Object> parameters = new ArrayList<Object>();

  public String getOperation() {
    return operation;
  }

  public void setOperation(String operation) {
    this.operation = operation;
  }

  public List<Object> getParameters() {
    return parameters;
  }

  public void setParameters(List<Object> parameters) {
    if (parameters == null) {
      this.parameters.clear();
    } else {
      this.parameters = parameters;
    }
  }

  public Object getParameter() {
    if (parameters.isEmpty()) {
      return null;
    } else {
      return parameters.get(0);
    }
  }

  public void setParameter(Object parameter) {
    parameters.clear();
    parameters.add(parameter);
  }

  public void addParameter(Object... parameters) {
    for (Object parameter : parameters) {
      this.parameters.add(parameter);
    }
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((operation == null) ? 0 : operation.hashCode());
    result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    QueryCondition other = (QueryCondition) obj;
    if (operation == null) {
      if (other.operation != null)
        return false;
    } else if (!operation.equals(other.operation))
      return false;
    if (parameters == null) {
      if (other.parameters != null)
        return false;
    } else if (!parameters.equals(other.parameters))
      return false;
    return true;
  }
}
